load("@aspect_rules_esbuild//esbuild:defs.bzl", "esbuild")
load("//tools:defaults.bzl", "http_server", "ng_project", "protractor_web_test_suite", "ts_project")

package(default_visibility = ["//visibility:public"])

ng_project(
    name = "sw_push_examples",
    srcs = glob(
        ["**/*.ts"],
        exclude = ["**/*_spec.ts"],
    ),
    deps = [
        "//:node_modules/zone.js",
        "//packages/core",
        "//packages/platform-browser",
        "//packages/service-worker",
    ],
)

ts_project(
    name = "sw_push_e2e_tests_lib",
    testonly = True,
    srcs = glob(["**/e2e_test/*_spec.ts"]),
    tsconfig = "//packages/examples:tsconfig_e2e",
    deps = [
        "//:node_modules/@types/jasminewd2",
        "//:node_modules/protractor",
        "//packages/examples/test-utils",
        "//packages/private/testing",
    ],
)

esbuild(
    name = "app_bundle",
    config = {
        "resolveExtensions": [".js"],
    },
    entry_point = ":main.ts",
    tsconfig = "//packages/examples:tsconfig_build",
    deps = [
        ":sw_push_examples",
        "//packages/examples:tsconfig_build",
    ],
)

http_server(
    name = "devserver",
    srcs = [
        "ngsw-worker.js",
        "//packages/examples:index.html",
    ],
    additional_root_paths = ["_main/packages/examples"],
    deps = [":app_bundle"],
)

protractor_web_test_suite(
    name = "protractor_tests",
    server = ":devserver",
    deps = [
        ":sw_push_e2e_tests_lib",
    ],
)

filegroup(
    name = "files_for_docgen",
    srcs = glob([
        "**/*.ts",
    ]),
)
